package titt.head.response;

import titt.head.HTTPHead;
import titt.head.HeadFactory;
import titt.head.Header;
import titt.head.util.AbstractHead;

public class FileHead extends AbstractHead {

	private String filename;

	public FileHead(String filename, HTTPHead h) {
		this(HeadFactory.createHead(h, new Header("Content-Disposition", "attachment; filename=\""+filename+"\"")));
	}
	
	public FileHead(HTTPHead h) {
		super.h = h;
		this.filename = h.getHeader("Content-Disposition").getValue().split("filename=")[1];
		if (filename.startsWith("\""))
			filename = filename.substring(1);
		if (filename.endsWith("\""))
			filename = filename.substring(0,filename.length()-1);
		filename = filename.split("\\\\")[filename.split("\\\\").length-1];
	}
	
	public String getFilename() {
		return filename;
	}
	
}
